package it.eng.area118.mdogpscollector;

import it.eng.area118.mdogpscollector.util.ViewUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ItemListActivity extends FragmentActivity {

	private boolean mTwoPane;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_item_list);
		// setContentView(R.layout.activity_item_twopane);

		if (findViewById(R.id.item_detail_container) != null) {
			mTwoPane = true;
			((ItemListFragment) getSupportFragmentManager().findFragmentById(R.id.item_list)).setActivateOnItemClick(true);
		}
		Button insertBt = ViewUtils.getView(this, R.id.btInsertCheckPoint);
		if (insertBt != null) {
			insertBt.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (mTwoPane) {
						InsertCheckPointFragment fragment = new InsertCheckPointFragment();
						FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
						// tr.setCustomAnimations(R.anim.slide_in_left,
						// R.anim.slide_out_right);
						tr.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
						tr.replace(R.id.item_detail_container, fragment).commit();

					} else {
						Intent detailIntent = new Intent(ItemListActivity.this, InsertCheckPointActivity.class);
						// detailIntent.putExtra(ItemDetailFragment.ARG_ITEM_ID,
						// id);
						startActivity(detailIntent);
					}
				}
			});
		}
	}

	// @Override
	// public void onItemSelected(String id) {
	// if (mTwoPane) {
	// Bundle arguments = new Bundle();
	// arguments.putString(ItemDetailFragment.ARG_ITEM_ID, id);
	// ItemDetailFragment fragment = new ItemDetailFragment();
	// fragment.setArguments(arguments);
	//
	// FragmentTransaction tr = getSupportFragmentManager()
	// .beginTransaction();
	// tr.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
	// tr.replace(R.id.item_detail_container, fragment).commit();
	//
	// } else {
	// Intent detailIntent = new Intent(this, ItemDetailActivity.class);
	// detailIntent.putExtra(ItemDetailFragment.ARG_ITEM_ID, id);
	// startActivity(detailIntent);
	// }
	// }
}
